//
//  BLES6_variables.h
//  BLES
//
//  Created by Khalid on 03/12/2014.
//  Copyright (c) 2014 Khalid. All rights reserved.
//

//#ifndef __BLES__BLES6__
//#define __BLES__BLES6__
//
//#include <stdio.h>
//
//#endif /* defined(__BLES__BLES6__) */
//
//
//#ifndef CEXMINIMISECOMPLIANCE_H_
//#define CEXMINIMISECOMPLIANCE_H_
//
//
//#endif /* CEXMINIMISECOMPLIANCE_H_ */


//int Solve(char* arg, char* filename);

#include "ls_types.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "EMatrix.h"
#include "Numbering.h"
#include "ABFG.h"
#include "Solve.h"
#include "Sens.h"
#include "Levels.h"
#include "Input.h"
#include "Output.h"



// argv[1] = input file

//printf("\n\n------*---Start of BLES Version 5.4 Program---*------\n");
int i,j,i2,j2,k,temp,temp2;	// incrementors
double ftemp;


// inital data arrays & structs
mesh inMesh;  // struct to hold mesh data
int numMat; // numberof materials
isoMat inMat[5]; // isotropic material - maximum of 5 different materials
levSet levelset; // struct to hold level set info
prob lsprob;  // struct to hold problem defintion
ctrl control; // struct to hold control data
int numCase;  // number load cases
double *load; // load vector (rhs)
bool sw;      // self-weight loading flag
Coord *acc;   // acceleration vector for self-weight loading
int *fixDof;  // fixed dof (turn into map)
int freeDof;  // number of free dof
sp_mat lump_mass; // lumped mass matrix

boundary Bndry;	// boundry discretization
Coord *gCoord;


/*------------------------------------------------------------------/
 /																	/
 /		Optimise structure boundary by the level set method			/
 /																	/
 /------------------------------------------------------------------*/

int itt; // Initalise number of itterations to 0
int itt0;
double oMax, oMin, obj_val;	 // varibale to compute convergence criterion
int ReCount;  // initialize reinitialization count
double cfl; // set time step modifier (for CFL condition)
//    double u11, u12, u21, u22, p1, p2; // displacement & load values - used for compliant mechanism design
double fact[6];

// Variables and arrays to store additional mesh data
int Ntot;		 // total nodes, including auxillary ones

// Arrays to store node data related to the optimisation
double *Nsens;  // pointer for node (+ aux node) sensitivity array
double *vol_sens; // volume sensitivity array (will be all 1's)
double *mass_sens; // mass sensitvitiy array
double *zero_sens; // when lsf does not influence a constraint
double *Vnorm;	// pointer for node (+ aux node) normal velocity array
double *Grad;   // pointer for lsf gradient info (using upwind scheme)


double *Lbound;   // array to store boundary intergral coefficents
int *Lbound_nums; // global node nums corresponding to Lbound entries
int num_Lbound;   // length of Lbound & Lbound_nums

// stuff for Ku = f solve using MA57 solver (& eigenvalue solver)
sp_mat Kg, Mg; // global stiffness and mass matrices

double *eig_vals, *eig_vecs; // arrays for eigenvalues and vectors
double *save_freq; // used to store freq values for output



double *disp; // displacement array
double *load_sw; // load vector, including self_weight load vector
double *adjont; // adjoint load (then disp) vector - for non-self adjoint problems

int num_adj; // number of adjoint cases to solve (objective, then in order of constraint list)

int num_sens;


double **prim_ptr; // vector, length = numCase (+ num_eig)
double **dual_ptr; // matrix row num = load case num, col num = dual state num
// or row = eigenvalue num, col = dual state num
double *wgt; // weights for load cases

double AreaElem;

double **KE;
double **ME;

double *alpha;
double **sens_ptr;
int *active;

int num_eig;
int comp_eig;
int order;
int numEnt;
int dispLen;
int loadLen;

double *obj;
double *cnstr;
double *delcon;
double *relax;
double *pred;
double *pred_temp;

char filename[100];


//int initialise(int argc, char *argv);
//
//void analysis(int itt);
//
//int sensitivity(void);
//
//void optimize(void);
//
//void output(void);
